package cn.ipanel.bigdata.job.basic

import cn.ipanel.bigdata.boot.Application
import cn.ipanel.bigdata.boot.date.{Date, Day, Hour}
import cn.ipanel.bigdata.dw.dim.phoenix.{T_CLASS_TAG, T_DEVICE}
import org.apache.spark.sql.ColumnName
import org.apache.spark.sql.functions.{col, exp, lit, sum}

import scala.collection.mutable.ListBuffer

/**
 * Author: lzz
 * Date: 2022/4/20 15:42
 */
object Task {

  lazy val DATE: Seq[String] = Seq("20211225", "20211226", "20211227", "20211228")

  def main(args: Array[String]): Unit = {
    // class tag 转换关系
//     Application.main(Array("job://basic.Class2Tag?date=20231123&name=lzz&age=30"))
    // 家庭统计
//    Application.main(Array("job://basic.HomeCt?date=20231129"))
    // 设备增量按类型统计
//    Application.main(Array("job://basic.DeviceIncrByTag?date=20231109"))
    // 设备按类型统计
//    Application.main(Array("job://basic.DeviceByTag?date=20231129"))

    // 日志清洗
//    Application.main(Array("job://ods.Report?date=20230101"))
//    Application.main(Array("job://ods.ReportByHour?hour=2023112400"))
    // 实时
        Application.main(Array("job://realtime.Realtime10"))
    //    Application.main(Array("job://realtime.Realtime1"))
//        Application.main(Array("job://realtime.Realtime60"))


//    Application.main(Array("job://basic.DeviceDetail?date=20230101"))
//    Application.main(Array("job://basic.HomeDetail?date=20230101"))
//    Application.main(Array("job://basic.AreaDetail?date=20231127"))

//    val now = Date.asToday
//    val TAG = T_CLASS_TAG
//    val D = T_DEVICE
//
//    val tagDf = TAG.load
//      .filter(col("f_date") === lit(now.prev().toDate))
//      .select(TAG.F_TAG, TAG.F_CLASS)
//      .withColumnRenamed(TAG.F_CLASS, "f_device_class")
//
//    // 补充 TAG 分类
//    val devideDf = D.load
//      .selectExpr(D.F_DEVICE_ID, D.F_REGION, D.F_DEVICE_CLASS)
//      .withColumnRenamed(D.F_DEVICE_ID, "f_device_id")
//      .withColumnRenamed(D.F_REGION, "f_region")
//
//    tagDf.show(false)
//    devideDf.show(false)
//
//    val df = tagDf.join(devideDf, Seq(D.F_DEVICE_CLASS))
//    df.show(1000, false)
//    df.filter(col("f_device_id").isin("152fa40239db452bb194bd756829aad0", "143fe0e34611450fb1fe4d5caaffd5b6", "05ea6a34aa1349f79c06481c8e0203d9")).show(false)

//    val today = Day("20231122")
//    println(today)
//    println(today.toDate)
//    println(today.asMonth.toSimpleDate)
//    println(today.asMonth.toSimpleMonth)
//    println(today.asMonth.toSimpleMinute)
//    println(today.asMonth.printFormat())
//    println(today.asMonth.next().printFormat())
  }
}